package com.wss.common.view.gallery;

import ohos.agp.components.Component;
import ohos.agp.components.ComponentContainer;
import ohos.agp.components.PageSliderProvider;

import java.util.List;

public class ImageViewerAdapter extends PageSliderProvider {

    private List<Component> views;

    public ImageViewerAdapter(List<Component> views) {
        this.views = views;
    }

    @Override
    public int getCount() {
        return views.size();
    }

    @Override
    public Object createPageInContainer(ComponentContainer componentContainer, int position) {
        componentContainer.addComponent(views.get(position));
        return views.get(position);
    }

    @Override
    public void destroyPageFromContainer(ComponentContainer componentContainer, int position, Object object) {
        if (position == 0 && views.size() == 0) {
            return;
        }
        if (position == views.size()) {
            componentContainer.removeComponent(views.get(--position));
        } else {
            componentContainer.removeComponent(views.get(position));
        }
    }

    @Override
    public boolean isPageMatchToObject(Component component, Object o) {
        return component == o;
    }
}
